package com.asa.voice.mp3.asa.decoder;

public class BitStream {
	  protected int bitPos;
	  
	  protected int bytePos;
	  
	  protected byte[] bitReservoir;
	  
	  private int endPos;
	  
	  private int maxOff;
	  
	  private int markPos;
	  
	  public BitStream(int paramInt1, int paramInt2) {
	    this.maxOff = paramInt1;
	    this.bitReservoir = new byte[paramInt1 + paramInt2];
	  }
	  
	  public int append(byte[] paramArrayOfbyte, int paramInt1, int paramInt2) {
	    if (paramInt2 + this.endPos > this.maxOff) {
	      System.arraycopy(this.bitReservoir, this.bytePos, this.bitReservoir, 0, this.endPos - this.bytePos);
	      this.endPos -= this.bytePos;
	      this.bitPos = this.bytePos = 0;
	    } 
	    if (paramInt2 + this.endPos > this.maxOff)
	      paramInt2 = this.maxOff - this.endPos; 
	    System.arraycopy(paramArrayOfbyte, paramInt1, this.bitReservoir, this.endPos, paramInt2);
	    this.endPos += paramInt2;
	    return paramInt2;
	  }
	  
	  public void feed(byte[] paramArrayOfbyte, int paramInt) {
	    this.bitReservoir = paramArrayOfbyte;
	    this.bytePos = paramInt;
	    this.bitPos = 0;
	  }
	  
	  public int get1Bit() {
	    int i = this.bitReservoir[this.bytePos] << this.bitPos;
	    i >>= 7;
	    i &= 0x1;
	    this.bitPos++;
	    this.bytePos += this.bitPos >> 3;
	    this.bitPos &= 0x7;
	    return i;
	  }
	  
	  public int getBits17(int paramInt) {
	    byte b = this.bitReservoir[this.bytePos];
	    int i = b << 8;
	    i |= this.bitReservoir[this.bytePos + 1] & 0xFF;
	    i <<= 8;
	    i |= this.bitReservoir[this.bytePos + 2] & 0xFF;
	    i <<= this.bitPos;
	    i &= 0xFFFFFF;
	    i >>= 24 - paramInt;
	    this.bitPos += paramInt;
	    this.bytePos += this.bitPos >> 3;
	    this.bitPos &= 0x7;
	    return i;
	  }
	  
	  public int getBits9(int paramInt) {
	    byte b = this.bitReservoir[this.bytePos];
	    int i = b << 8;
	    i |= this.bitReservoir[this.bytePos + 1] & 0xFF;
	    i <<= this.bitPos;
	    i &= 0xFFFF;
	    i >>= 16 - paramInt;
	    this.bitPos += paramInt;
	    this.bytePos += this.bitPos >> 3;
	    this.bitPos &= 0x7;
	    return i;
	  }
	  
	  public int getBytePos() {
	    return this.bytePos;
	  }
	  
	  public int getSize() {
	    return this.endPos;
	  }
	  
	  public void skipBytes(int paramInt) {
	    this.bytePos += paramInt;
	    this.bitPos = 0;
	  }
	  
	  public void skipBits(int paramInt) {
	    this.bitPos += paramInt;
	    this.bytePos += this.bitPos >> 3;
	    this.bitPos &= 0x7;
	  }
	  
	  protected void mark() {
	    this.markPos = this.bytePos;
	  }
	  
	  protected int getMark() {
	    return this.bytePos - this.markPos;
	  }
	}